<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}admin/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}admin/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}admin/static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="{{env('APP_URL')}}css/pagination.css"/>
    <title>用户列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 权限管理
    <span class="c-gray en">&gt;</span> 权限列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

{{-- 消息提示 --}}
@include('admin.common.msg')

<div class="page-container">
    <div class="text-c">
        <form action="{{route('admin.auth.index')}}" method="get">
            @csrf
            <input type="text" class="input-text" style="width:250px" placeholder="输入权限名" id="name" name="name"
                   value="{{$name}}">
            <button type="submit" id="select" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i>
                搜权限
            </button>
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a class="btn btn-danger radius" onclick="deleteAll()">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
            </a>
            <a class="btn btn-primary radius" href="{{route('admin.auth.create')}}">
                <i class="Hui-iconfont">&#xe600;</i> 添加权限
            </a>
        </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="" value=""></th>
                <th width="80">ID</th>
                <th >权限名</th>
                <th>路由别名</th>
                <th>上级权限ID</th>
                <th>是否菜单权限</th>
                <th >加入时间</th>
                <th >操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $item)
                <tr class="text-c">
                    <td>
                        <input type="checkbox" value="{{ $item['id'] }}" name="id[]">
                    </td>
                    <td>{{ $item['id']}}</td>
                    <td class="text-l">{{ $item['auth_name'] }}</td>
                    <td>{{ $item['route_name'] }}</td>
                    <td>{{$item['pid']}}</td>
                    <td>@if($item['is_menu'])是@else否@endif</td>
                    <td>{{ $item['created_at'] }}</td>
                    <td class="td-manage">
                        <a href="{{ route('admin.auth.edit',['id' => $item['id']]) }}"
                           class="label label-secondary radius">修改</a>
                        <a href="{{ route('admin.auth.destroy',['id' => $item['id']]) }}"
                           class="label label-danger radius delbtn">删除</a>
                    </td>
                </tr>
                @foreach($item['son'] as $item1)
                    <tr class="text-c">
                        <td>
                            <input type="checkbox" value="{{ $item1['id'] }}" name="id[]">
                        </td>
                        <td>{{ $item1['id']}}</td>
                        <td class="text-l">|--{{ $item1['auth_name'] }}</td>
                        <td>{{ $item1['route_name'] }}</td>
                        <td>{{$item1['pid']}}</td>
                        <td>@if($item1['is_menu'])是@else否@endif</td>
                        <td>{{ $item1['created_at'] }}</td>
                        <td class="td-manage">
                            <a href="{{ route('admin.auth.edit',['id' => $item1['id']]) }}"
                               class="label label-secondary radius">修改</a>
                            <a href="{{ route('admin.auth.destroy',['id' => $item1['id']]) }}"
                               class="label label-danger radius delbtn">删除</a>
                        </td>
                    </tr>

                    @foreach($item1['son'] as $item2)
                        <tr class="text-c">
                            <td>
                                <input type="checkbox" value="{{ $item2['id'] }}" name="id[]">
                            </td>
                            <td>{{ $item2['id']}}</td>
                            <td class="text-l">|----{{ $item2['auth_name'] }}</td>
                            <td>{{ $item2['route_name'] }}</td>
                            <td>{{$item2['pid']}}</td>
                            <td>@if($item2['is_menu'])是@else否@endif</td>
                            <td>{{ $item2['created_at'] }}</td>
                            <td class="td-manage">
                                <a href="{{ route('admin.auth.edit',['id' => $item2['id']]) }}"
                                   class="label label-secondary radius">修改</a>
                                <a href="{{ route('admin.auth.destroy',['id' => $item2['id']]) }}"
                                   class="label label-danger radius delbtn">删除</a>
                            </td>
                        </tr>
                    @endforeach

                @endforeach
            @endforeach
            </tbody>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="{{env('APP_URL')}}admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="{{env('APP_URL')}}admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="{{env('APP_URL')}}admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="{{env('APP_URL')}}admin/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{env('APP_URL')}}admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="{{env('APP_URL')}}admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="{{env('APP_URL')}}admin/lib/laypage/1.2/laypage.js"></script>
<script>
    // 生成一个token crsf
    const _token = "{{ csrf_token() }}";
    // 给删除按钮绑定事件
    $('.delbtn').click(async  function (evt) {
        // 得到请求的url地址
        let url = $(this).attr('href');
        // 发起一个delete请求
        let {code,msg} = await $.ajax({
            url,
            data: {_token},
            type: 'DELETE',
        });
        if (code == 200){
            window.location.reload();
        }
        if (code == 400){
            layer.msg(msg);
        }
        return false;
    });

    function deleteAll() {
        let ids = $("input[name='id[]']:checked");
        let id = [];
        let url = "{{route('admin.user.delAll')}}";
        $.each(ids, function (key, value) {
            id.push($(value).val());
        });

        layer.confirm('是否批量删除这些数据？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            if (id.length > 0) {
                $.ajax({
                    url,
                    data: {id, _token},
                    type: 'DELETE'
                }).then(({status, msg}) => {
                    layer.msg(msg, {time: 2000, icon: 1}, () => {
                        // 删除当前行
                        window.location.reload();
                    });
                });
            }
        });
    }

</script>
</body>
</html>